package cn.chrilwe.pigpig.im.client;

import java.net.URI;
import java.net.URISyntaxException;

import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import com.alibaba.fastjson.JSON;

import cn.chrilwe.pigpig.im.protocol.TalkRequest;

public class WsClient {

	public static void main(String[] args) throws URISyntaxException, InterruptedException {
		WebSocketClient client = new WebSocketClient(new URI("ws://192.168.43.163:9999/ws")) {
			
			@Override
			public void onOpen(ServerHandshake handshakedata) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onMessage(String message) {
				System.out.println(message);
			}
			
			@Override
			public void onError(Exception ex) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onClose(int code, String reason, boolean remote) {
				// TODO Auto-generated method stub
				
			}
		};
		
		client.connectBlocking();
		TalkRequest request = new TalkRequest();
		request.setMsg("hello");
		request.setRoomId(1);
		request.setToken("123");
		client.send(JSON.toJSONString(request));
	}
}
